package web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.annotation.SuppressLint;
import android.os.StrictMode;

public class ListproductsUserInput {
	
	
		String finalresponse;
		
		
		@SuppressLint("NewApi")
		public String getallproducts(String Nameq){
		
		HttpClient httpclient = new DefaultHttpClient();
		
		String Url="http://wheresmymaggi.net78.net/listproductsUserInput.php?Nameq=" + Nameq; 
		
	    HttpGet httpget = new HttpGet(Url);
	   
	    if (android.os.Build.VERSION.SDK_INT > 9) {
		    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		    StrictMode.setThreadPolicy(policy);
		}
	   
	    try {	    		        


	        // Execute HTTP Post Request
	        HttpResponse response = httpclient.execute(httpget);
	       
	        
	        HttpEntity entity = response.getEntity();
	        
	        
	        InputStream is = entity.getContent();
	        
	       
	        finalresponse=convertStreamToString(is);
	       
	        RemoveExtraCode R1= new RemoveExtraCode();
	        finalresponse= R1.removeExtra(finalresponse);
	        
	      
	    }
	    catch(Exception E){
	    	System.out.print(E.toString());
	    	
	    }
	    finally{
	    	
	    }
	    return finalresponse;
	    
	    

		}
		
		private static String convertStreamToString(InputStream is) {
			
		    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		    StringBuilder sb = new StringBuilder();
		
		    String line = null;
		    try {
		        while ((line = reader.readLine()) != null) {
		            sb.append((line + "\n"));
		        }
		    } catch (IOException e) {
		        e.printStackTrace();
		    } finally {
		        try {
		            is.close();
		        } catch (IOException e) {
		            e.printStackTrace();
		        }
		    }
		    return sb.toString();
			}
		
}
